package grupo5;

import java.io.*;

public class Writer {

	public Writer(Instruction[] instrucciones) throws IOException {
		File outFile = new File("output.txt");
		FileWriter out = new FileWriter(outFile);
		BufferedWriter out2 = new BufferedWriter(out);

		out2.write("library ieee;\n");
		out2.write("use ieee.std_logic_1164.all;\n");
		out2.write("use ieee.numeric_std.all;\n\n");
		out2.write("entity ROM is\n");
		out2.write("  port ( address : in std_logic_vector(6 downto 0);\n");
		out2.write("         data : out std_logic_vector(24 downto 0) );\n");
		out2.write("end entity ROM;\n\n");
		out2.write("architecture behavioral of ROM is\n");
		out2.write("  type mem is array ( 0 to 127) of std_logic_vector(24 downto 0);\n");
		out2.write("  constant my_Rom : mem := (\n\n");
		int i=0;
		boolean escrito=false;
		while (i<=127){
			if(!escrito){
				for(int j=0; j<instrucciones.length; j++){
					out2.write(j+" => \""+instrucciones[i].imprimir()+"\",\n");
					i++;
				}
			}
			escrito = true;
			if(i==127){
			out2.write(i+" => \"0000000000000000000000000\");\n");
			}else{
			out2.write(i+" => \"0000000000000000000000000\",\n");
			}
			i++;
		}
		out2.write("\n");
		out2.write("begin\n");
		out2.write("   process (address)\n");
		out2.write("   begin\n");
		out2.write("    data <= my_Rom(to_integer(unsigned(address)));\n");
		out2.write("  end process;\n");
		out2.write("end architecture behavioral;\n");

		out2.close();
		out.close();
		
	}

}